<template>
  增加招聘信息
  <el-form ref="form" :model="form" label-width="80px">
    <el-form-item label="职位名称">
      <el-input v-model="form.name"></el-input>
    </el-form-item>
    <el-form-item label="工作地点">
      <el-cascader
        placeholder="试试搜索：北京"
        :options="options"
        :props="{ checkStrictly: true }"
        @change="gaibianaddress"
        filterable
      ></el-cascader>
    </el-form-item>
    <el-form-item label="学历限制">
      <el-radio-group v-model="form.xueli">
        <el-radio :label="1">不限学历</el-radio>
        <el-radio :label="2">小学</el-radio>
        <el-radio :label="3">初中</el-radio>
        <el-radio :label="4">高中/中专</el-radio>
        <el-radio :label="5">大专</el-radio>
        <el-radio :label="6">本科</el-radio>
        <el-radio :label="7">硕士</el-radio>
        <el-radio :label="8">博士</el-radio>
      </el-radio-group>
    </el-form-item>
    <el-form-item label="招聘人数">
      <el-input-number
        v-model="form.zhaopinnum"
        @change="handleChange"
        :min="1"
        :max="10"
        label="描述文字"
      ></el-input-number>
    </el-form-item>
    <el-form-item label="工作经验">
    <el-input v-model="form.jingyan" placeholder="请输入内容"></el-input>
    </el-form-item>
    <el-form-item label="职位要求">
      <el-input type="textarea" v-model="form.desc" :rows="10"></el-input>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="onSubmit">立即创建</el-button>
      <el-button @click="quxiao">取消</el-button>
    </el-form-item>
  </el-form>
</template>
<script>
import province from "../../static/json/province.json";
import city from "../../static/json/city.json";
import area from "../../static/json/area.json";
export default {
  name: "AddZhaoPin",
  props: ["jwttoken"],
  data() {
    return {
      form: {
        name: "",
        address: "",
        xueli: 1,
        zhaopinnum: 1,
        jingyan:"",
        desc: "",
      },
      options: [],
    };
  },
  methods: {
    quxiao:function(){
      this.$router.push("/ZhaoPinList")
    },
    gaibianaddress: function (evt) {
      console.log(evt);
      let address = "";
      for (let c in evt) {
        address = address + evt[c] + "-";
      }
      address = address.substr(0, address.length - 1);
      this.form.address = address;
    },
    onSubmit: function () {
      if (this.form.name == "") {
        this.$notify({
          title: "警告",
          message: "请输入职位名称",
          type: "warning",
        });
        return false;
      }
      if (this.form.address == "") {
        this.$notify({
          title: "警告",
          message: "请选择工作地点",
          type: "warning",
        });
        return false;
      }
      if (this.form.desc == "") {
        this.$notify({
          title: "警告",
          message: "请填写职位描述",
          type: "warning",
        });
        return false;
      }
      if (this.form.jingyan == "") {
        this.$notify({
          title: "警告",
          message: "请填写经验",
          type: "warning",
        });
        return false;
      }

      console.log(this.jwttoken);
      let that = this;
      this.$jquery.ajax({
        async: false,
        type: "POST",
        dataType: "json",
        url: this.$baseurl + "addRecruit",
        beforeSend: function (request) {
          request.setRequestHeader("Authorization", that.jwttoken);
        },
        data: {
          name: this.form.name,
          address: this.form.address,
          xueli: this.form.xueli,
          zhaopinnum: this.form.zhaopinnum,
          jingyan: this.form.jingyan,
          desc: this.form.desc,
        },
        success: function (rtn) {
          if (rtn.code == -5) {
            that.$emit("loginstate1", -1);
          }
          if (rtn.code == 1) {
            that.$notify({
              title: "成功",
              message: "创建成功",
              type: "success",
            });
            setTimeout(() => {
              that.$router.push("/ZhaoPinList")
            }, 2000);
          } else {
            that.$notify.info({
              title: "消息",
              message: "创建失败",
            });
          }
        },
      });
    },
  },
  created: function () {
    this.options = province;
    for (let i in province) {
      province[i]["label"] = province[i]["name"];
      province[i]["value"] = province[i]["name"];
      province[i].children = [];
      for (let i1 in city[province[i]["id"]]) {
        let city1 = {};
        city1.label = city[province[i]["id"]][i1].name;
        city1.value = city[province[i]["id"]][i1].name;
        city1.children = [];
        for (let i2 in area[city[province[i]["id"]][i1].id]) {
          let id2 = area[city[province[i]["id"]][i1].id];
          let area1 = {};
          area1.label = id2[i2].name;
          area1.value = id2[i2].name;
          city1.children.push(area1);
        }
        province[i].children.push(city1);
      }
    }
  },
};
</script>
